/*
 * CS_SOCIAL_RECOMMEND_FRIEND_LIST.cpp
 *
 *  Created on: 2013. 5. 27.
 *      Author: the2
 */


#include "../../Command.h"
#include "../../User.h"
#include "../../Proxy.h"
#include "../../../../protocol/iFriends.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_SOCIAL_RECOMMEND_FRIEND_LIST(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;
//	RecommendSyn msg;
//	msg.gid = 0;
	uint32_t target_userseq = 0;

	auto & usertree = ::ProjectZ::NProxy::GetUserTree();

	for(int i = 0; i < 3; i++)
	{
		auto iter = usertree.begin();

		std::advance( iter, rand() % usertree.size() );

		if(iter->first == pUser->GetUserSeq())
			continue;
		else
		{
			target_userseq = iter->first;
			break;
		}
	}

	if(0 == target_userseq)
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(ACK_OK)
						<< static_cast<uint32_t>(0)		// gid
						<< static_cast<uint32_t>(0)		// score
						<< ""		// nickname
						<< "";		// profile_url

		pAck->MakePacket(CMD_SC_SOCIAL_RECOMMEND_FRIEND_LIST);
		pUser->Send(pAck);
		return;
	}

	AllowFriendSyn msg;
	msg.userseq = pUser->GetUserSeq();
	msg.msgid = RecommendSyn::MSG_ID;

	::ProjectZ::NProxy::SendFriendsServer(target_userseq, msg);
}

} /*NCommand*/ } /*ProjectZ*/
